package com.gift.recommendation.modules.user.controller;

import com.gift.recommendation.Base.BaseResponse;
import com.gift.recommendation.modules.user.biz.AddressBiz;
import com.gift.recommendation.modules.user.biz.ProvinceBiz;
import com.gift.recommendation.modules.user.dto.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author zzh <2658137258@qq.com>
 * @date 2023/2/16
 */
@RestController
@RequestMapping("/gift/address")
@Api(tags = "快递地址管理")
@Validated
public class AddressController {

    @Autowired
    private AddressBiz addressBiz;

    @Autowired
    private ProvinceBiz provinceBiz;

    @ApiOperation(value = "查询省份")
    @RequestMapping(path = "/list-province",method = RequestMethod.GET)
    public BaseResponse listProvince(){
        ProvinceRsp result = provinceBiz.getListProvince();
        return BaseResponse.success(result);
    };

    @ApiOperation(value = "查询市")
    @RequestMapping(path = "/list-city",method = RequestMethod.POST)
    public BaseResponse listCity(@RequestBody ProvinceReq req){
        ProvinceRsp result = provinceBiz.getlistCity(req);
        return BaseResponse.success(result);
    };

    @ApiOperation(value = "查询区")
    @RequestMapping(path = "/list-area",method = RequestMethod.POST)
    public BaseResponse listArea(@RequestBody ProvinceReq req){
        ProvinceRsp result = provinceBiz.getListArea(req);
        return BaseResponse.success(result);
    };

    @ApiOperation(value = "查询街道")
    @RequestMapping(path = "/list-town",method = RequestMethod.POST)
    public BaseResponse listTown(@RequestBody ProvinceReq req){
        ProvinceRsp result = provinceBiz.getListTown(req);
        return BaseResponse.success(result);
    };

    @ApiOperation(value = "添加快递地址信息")
    @RequestMapping(path = "/add",method = RequestMethod.POST)
    public BaseResponse add(@RequestBody AddressReq req){
        addressBiz.add(req);
        return BaseResponse.success();
    };

    @ApiOperation(value = "查找快递地址信息列表")
    @RequestMapping(path = "/list",method = RequestMethod.POST)
    public BaseResponse list(@RequestBody AddressReq req){
        List<AddressRsp> result = addressBiz.list(req);
        return BaseResponse.success(result);
    };

    @ApiOperation(value = "根据uuid获取快递地址信息")
    @RequestMapping(path = "/get",method = RequestMethod.POST)
    public BaseResponse getById(@RequestBody AddressReq req){
        AddressRsp result = addressBiz.getById(req);
        return BaseResponse.success(result);
    };

    @ApiOperation(value = "根据uuid删除快递地址信息")
    @RequestMapping(path = "/delete",method = RequestMethod.POST)
    public BaseResponse delete(@RequestBody AddressReq req){
        addressBiz.delete(req);
        return BaseResponse.success();
    };

    @ApiOperation(value = "根据uuid修改快递地址信息")
    @RequestMapping(path = "/update",method = RequestMethod.POST)
    public BaseResponse update(@RequestBody AddressReq req){
        addressBiz.update(req);
        return BaseResponse.success();
    };

    @ApiOperation(value = "根据uuid设置默认收货地址")
    @RequestMapping(path = "/default",method = RequestMethod.POST)
    public BaseResponse isDefault(@RequestBody AddressReq req){
        addressBiz.isDefault(req);
        return BaseResponse.success();
    };

    @ApiOperation(value = "查找默认收货地址")
    @RequestMapping(path = "/search-default",method = RequestMethod.POST)
    public BaseResponse searchDefault(@RequestBody AddressReq req){
        AddressRsp addressRsp = addressBiz.searchDefault(req);
        return BaseResponse.success(addressRsp);
    };
}
